<template>
  <div>
    <div class="center">
      <el-row :gutter="20">
        <el-col :span="10">
          <div class="block">
            <el-timeline>
              <el-timeline-item v-for="item in this.list"  :key="item.plan_uuid" :timestamp="item.first_time" placement="top">
                <el-card>
                  <div class="fr"><el-button type="warning" size="mini">{{item.plan_type_title}}</el-button></div>
                  <h4>{{item.title}}</h4>
                  <br>
                  <el-button v-if="menuList.includes('showReportStudent')" type="primary" size="mini" round @click="lookReport(item)">查看报告</el-button>
                </el-card>
              </el-timeline-item>
            </el-timeline>
          </div>
        </el-col>
      </el-row>
    </div>
    <el-dialog title="详情" :visible.sync="dialogVisible" width="30%" :close-on-click-modal='false'>
      <div v-for="item in dialogList" :key="item.id">
        <el-button type="text" @click="checkReport(item)">{{item.title}}</el-button>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {APIGETASSESSMENTRECORDS} from '@/common/api.js'
export default {
  props: ['id'],
  data () {
    return {
      menuList: [],
      list: [],
      dialogVisible: false,
      dialogList: []
    }
  },
  created () {
    this.getData()
    this.menuList = sessionStorage.getItem('list')
  },
  methods: {
    getData () {
      APIGETASSESSMENTRECORDS({
        uid: this.id
      }).then((res) => {
        if (res.status === 1) {
          this.list = res.data
        }
      }).catch((err) => {
        this.$message.error(err.msg)
      })
    },
    lookReport (val) {
      this.dialogVisible = true
      this.dialogList = val.sub_list
      if (val.plan_type === 3 || val.plan_type === 2) {
        this.dialogList.forEach(item => {
          if (item.id === 925984) { // 六大兴趣
            item.hrefStr = '/api/report/sixInterest'
          } else if (item.id === 181731) { // 职业价值观
            item.hrefStr = '/api/report/professionalValue'
          } else if (item.id === 132462) { // MBTI
            item.hrefStr = '/api/report/MBTICharacter'
          } else if (item.id === 329235) { // 九大智能高中版
            item.hrefStr = '/api/report/nineSmart'
          } else if (item.id === 689942) { // 九大智能初中版
            item.hrefStr = '/api/report/nineSmart'
          } else if (item.id === 867971) { // 中学生问题解决能力量表
            item.hrefStr = '/api/report/problemSolving'
          } else if (item.id === 756492) { // 中学生沟通能力量表
            item.hrefStr = '/api/report/communicationSkills'
          } else if (item.id === 976297) { // 学生人际合作能力评估报告
            item.hrefStr = '/api/report/InterpersonalCooperation'
          } else { // 单个量表
            item.hrefStr = '/api/report/getIndividualReportView'
          }
          item.report_id = val.report_id
          item.token = window.sessionStorage.getItem('token')
        })
      } else if (val.plan_type === 1) {
        this.dialogList.forEach(item => {
          item.hrefStr = '/api/report/getRecommendIndividualReportView'
          item.report_id = val.report_id
          item.token = window.sessionStorage.getItem('token')
        })
      }
    },
    checkReport (row) {
      window.open(row.hrefStr + '?report_id=' + row.report_id + '&sid=' + row.id + '&token=' + row.token)
      this.dialogVisible = false
    }
  }
}
</script>
